<?php

namespace App\Http\Controllers\Api;

use App\Exports\HuiBuyExport;
use App\Exports\MemberdrawExport;
use App\Exports\MemberdrawGroupExport;
use App\Exports\TixianExport;
use App\Http\Controllers\Controller;
use App\Jobs\CompletedExport;
use App\Models\Members;
use App\Models\Members\MemberDraw;
use App\Models\Members\MemberPipeline;
use App\Models\Rooms\RoomsGooodsBuy;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;

class ExportController extends Controller
{
    protected  $filename;

    public function __construct()
    {
        $this->filename = Date('Ymd').'/'.Str::random().'.xlsx';
    }

    //回购导出
    public function huibuy()
    {
        (new HuiBuyExport(new RoomsGooodsBuy()))->queue($this->filename,'public')->chain([
            new CompletedExport($this->filename,'回购申请导出-'.now()->toDateString(),Auth::user())
        ]);

        return $this->success(['message' => '正在导出中,请稍后！']);
    }

    //提现申请
    public function tixian()
    {
        (new TixianExport(new MemberDraw()))->queue($this->filename,'public')->chain([
            new CompletedExport($this->filename,'提现申请导出-'.now()->toDateString(),Auth::user())
        ]);

        return $this->success(['message' => '正在导出中,请稍后！']);
    }


    //个人流水导出
    public function memberdraw()
    {
        $nickname = Members::where('id',request()->id)->value('nickname');
        (new MemberdrawExport(new MemberPipeline()))->queue($this->filename,'public')->chain([
            new CompletedExport($this->filename,$nickname.'-个人流水导出-'.now()->toDateString(),Auth::user())
        ]);

        return $this->success(['message' => '正在导出中,请稍后！']);
    }

     //团队导出
    public function memberdrawgroup()
    {
        $nickname = Members::where('id',request()->id)->value('nickname');
        (new MemberdrawGroupExport(new Members()))->queue($this->filename,'public')->chain([
            new CompletedExport($this->filename,$nickname.'-团队流水导出-'.now()->toDateString(),Auth::user())
        ]);

        return $this->success(['message' => '正在导出中,请稍后！']);
    }
}
